import * as PIXI from 'pixi.js'
// import * as turf from '@turf/turf';

// declare global {
//     interface Window {
//         turf: any
//     }
// }

// declare global {
//     interface Window {
//         turf:any;
//     }
// }

// let turf = window.turf; // ok now


export default class PointTooler{

    static getBounds(points:PIXI.Point[]){
        var bounds = new PIXI.Bounds();
        points.forEach(item => bounds.addPoint(item));
        return bounds;
    }

    static scalePolygon0(points:PIXI.Point[], scale:number){
        var list:any[] = [];
        points.forEach(item => {
            list.push([Number(item.x.toFixed(2)), Number(item.y.toFixed(2))]);
        })
        list.push([Number(points[0].x.toFixed(2)), Number(points[0].y.toFixed(2))]);
        console.log([list]);
        // var poly = window.turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
        var poly = window.turf.polygon([list]);
        console.log(poly, "poly");
        var scaledPoly:any = window.turf.transformScale(poly, scale);
        return scaledPoly.geometry.coordinates;
    }

    static scalePolygon(points:PIXI.Point[], scaleX:number, scaleY:number){
        points.forEach(item => {
            if(Array.isArray(item)){
                item[0] *= scaleX;
                item[1] *= scaleY;
            }
            else{
                item.x *= scaleX;
                item.y *= scaleY;
            }
        })
    }

    static offsetPolygon(points:any[], x:number, y:number){
        points.forEach(item => {
            if(Array.isArray(item)){
                item[0] += x;
                item[1] += y;
            }
            else{
                item.x += x;
                item.y += y;
            }
        })
    }

    static toString(points:any[]):string{
        var list:any[] = [];
        points.forEach(item => {
            if(Array.isArray(item)){
                list.push(item[0], item[1]);
            }
            else{
                list.push(item.x, item.y);
            }
        })
        return list.join(",");
    }
}